<!DOCTYPE html>
<html>
<head>
    <title>挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
<!--    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
    $(function () {       
		$('#backid').click(function(){
				window.location.href="index.html";
		 });
    });
    var pageNumber ,pageSize;
    function getUrl(url,name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = url.split("?")[1].match(reg);
        //    var r = url.split(name+"=")[1].split("!")[0];
        if (r != null)
            return decodeURI(r[2]);
        return null;
    }
    function back(){
        window.location.href="/registration/index.html?pageNumber="+pageNumber+"&pageSize="+pageSize;
    }
    $(function () {
        //根据地址获取teamId,如果null则执行增加，否则执行更新
        let url = document.location.toString();//获取URL
        // let hosR_id=url.GetValue("hosR_id");
        // let pageNumber=url.GetValue("pageNumber");
        // let pageSize=url.GetValue("pageSize");
        let hosR_id = getUrl(url,"hosR_id");
        pageNumber = getUrl(url,"pageNumber");
        pageSize = getUrl(url,"pageSize");
        //链接带后缀！用
        //alert(teamId);
        //根据id查询要更新的球队信息并回显到页面
        queryById(hosR_id);

    });
    function queryById(id) {
        document.getElementById("editHosR_id").setAttribute("value",id)
        //$("#hosR_id").val(id)
        $.ajax({
            type: "GET",
            url: "/hosregister/listByKey.do", //RESTful风格的API定义
            data: $("#myForm").serialize(),
            success: function (vo) {
                let obj = vo.obj;
                let hosR_id = obj.hosR_id == null ? "" : obj.hosR_id;
                let hosR_idCar = obj.hosR_idCar == null ? "" : obj.hosR_idCar;
                let horR_regPrice = obj.hosR_regPrice == null ? "" : obj.hosR_regPrice;
                let horR_medical = obj.hosR_medical == null ? "" : obj.hosR_medical;
                let hosR_phone = obj.hosR_phone == null ? "" : obj.hosR_phone;
                let hosR_age = obj.hosR_age == null ? "" : obj.hosR_age;
                let hosR_work = obj.hosR_work == null ? "" : obj.hosR_work;
                let d_keshi = obj.doctor.d_keshi == null ? "" : obj.doctor.d_keshi;
                let d_name = obj.doctor.d_name == null ? "" : obj.doctor.d_name;
                let hosR_remark = obj.hosR_remark == null ? "" : obj.hosR_remark;
                var str = "<tr>\n        <td width=\"10%\" class=\"tableleft\">姓名</td>\n       " +
                    " <td><input type=\"text\" name=\"hosR_id\" value=" + hosR_id + "></td>\n    </tr>\n\n " +
                    "   <tr>\n        <td width=\"10%\" class=\"tableleft\">身份证号</td>\n   " +
                    "     <td><input type=\"text\" name=\"hosR_idCar\" value=" + hosR_idCar + "></td>\n   </tr>\n   " +
                    " <tr>\n        <td width=\"10%\" class=\"tableleft\">挂号费</td>\n    " +
                    "    <td><input type=\"text\" name=\"hosR_regPrice\" value=" + horR_regPrice + ">元</td>\n    " +
                    "</tr>\n    <tr>\n        <td width=\"10%\" class=\"tableleft\">社保号</td>\n     " +
                    "   <td><input type=\"text\" name=\"hosR_medical\" value=" + horR_medical + "></td>\n    </tr>\n " +
                    "   <tr>\n        <td width=\"10%\" class=\"tableleft\">联系电话</td>\n    " +
                    "    <td><input type=\"text\" name=\"hosR_phone\" value=" + hosR_phone + "></td>\n    </tr>\n   " +
                    " <tr>\n        <td width=\"10%\" class=\"tableleft\">是否自费</td>\n      " +
                    "  <td><input type=\"radio\" name=\"hosR_selfPrice\" value=\"1\" id=\"radioNo\"checked/>否&nbsp;&nbsp;&nbsp;" +
                    "<input type=\"radio\" name=\"hosR_selfPrice\" id=\"radioYes\" value=\"0\"/>是</td>\n    </tr>\n  " +
                    "  <tr>\n        <td width=\"10%\" class=\"tableleft\">性别</td>\n    " +
                    "    <td><input type=\"radio\" name=\"hosR_sex\" value=\"0\" checked/>男&nbsp;&nbsp;&nbsp;" +
                    "<input type=\"radio\" name=\"hosR_sex\" value=\"1\"/>女</td>\n    </tr>\n   " +
                    " <tr>\n        <td width=\"10%\" class=\"tableleft\">年龄</td>\n     " +
                    "   <td><input type=\"text\" name=\"hosR_age\" value=" + hosR_age + "></td>\n    </tr>\n " +
                    "   <tr>\n        <td width=\"10%\" class=\"tableleft\">职业</td>\n    " +
                    "    <td><input type=\"text\" name=\"hosR_work\" value=" + hosR_work + "></td>\n    </tr>\n    " +
                    "<tr>\n        <td width=\"10%\" class=\"tableleft\">初复诊</td>\n        " +
                    "<td><input type=\"radio\" name=\"hosR_lookDoctor\" value=\"0\" checked/>初诊&nbsp;&nbsp;&nbsp;" +
                    "<input type=\"radio\" name=\"hosR_lookDoctor\" value=\"1\"/>复诊</td>\n   </tr>\n  " +
                    "  <tr id='selKeshi'>\n        <td width=\"10%\" class=\"tableleft\">所挂科室</td>\n        " +
                    "<td><select name='selectKeshi' id='selectKeshi' ><option>急诊科</option><option>骨科</option><option>血液科</option></select></td>\n </tr>\n " +
                    "   <tr>\n        <td width=\"10%\" class=\"tableleft\">指定医生</td>\n       " +
                    " <td><select id='selectDoctor' name='selectDoctor'><option>程俊</option><option>欧阳雨露</option><option>王博</option></select></td>\n    </tr>\n" +
                    "	<tr>\n        <td width=\"10%\"  class=\"tableleft\">备注</td>\n   " +
                    "     <td><textarea name='hosR_state'>" + hosR_remark + "</textarea></td>\n	</tr>\n   " +
                    " <tr>\n        <td colspan=\"2\">\n			<center>\n		" +
                    "		<button type=\"submit\" class=\"btn btn-primary\" type=\"button\" onclick='update()'>保存</button> &nbsp;&nbsp;" +
                    "<button type=\"button\" class=\"btn btn-success\" name=\"backid\" id=\"backid\" onclick='back()'>返回列表</button>\n			</center>\n	" +
                    "	</td>\n    </tr>";
                $("#tboby").html(str);
                if (obj.hosR_selfPrice != null && obj.hosR_selfPrice == 1) {
                    document.all.hosR_selfPrice[0].checked = true;
                    //document.getElementById("#radioNo").setAttribute("checked", "checked");
                } else {
                    document.all.hosR_selfPrice[1].checked = true;
                    //document.getElementById("#radioYes");
                    //setAttribute("checked", "checked");
                }
                if (obj.hosR_sex != null && parseInt(obj.hosR_sex) == 1) {
                    document.all.hosR_sex[1].checked = true;
                    //document.getElementById("#radioNo").setAttribute("checked", "checked");
                } else {
                    document.all.hosR_sex[0].checked = true;
                    //document.getElementById("#radioYes");
                    //setAttribute("checked", "checked");
                }
                if (obj.hosR_lookDoctor != null && parseInt(obj.hosR_lookDoctor) == 1) {
                    document.all.hosR_lookDoctor[1].checked = true;
                    //document.getElementById("#radioNo").setAttribute("checked", "checked");
                } else {
                    document.all.hosR_lookDoctor[0].checked = true;
                    //document.getElementById("#radioYes");
                    //setAttribute("checked", "checked");
                }
                $.ajax({
                    type: "GET",
                    url: "/hosregister/listKeshi.do", //RESTful风格的API定义
                    data: "",
                    success: function (vo) {
                          let map =  vo.map;
                          var options = "";
                        for( var key in map) {
                           var option = "<option value="+key+">"+key+"</option>";
                           options+=option;
                        }
                        var str3 =  " <td width=\"10%\" class=\"tableleft\">所挂科室</td>\n        " +
                            "<td><select name='selectKeshi' id='selectKeshi' onchange='change()'>"+options+"</select></td>\n  ";
                    $("#selKeshi").html(str3);

                        $("select[name='selectKeshi']").change(function(){
                            // 先清空第二个
                                $("select[name='selectDoctor']").empty();
                           var keshi =  $("#selectKeshi").find("option:selected").text();
                           if(map[keshi] != null){
                               var str = "";
                               var list = map[keshi];
                               for(var i = 0; i < list.length; i++){
                                   var s = list[i];
                                   str += "<option value='"+s+"'>"+s+"</option>";
                               }
                               $("#selectDoctor").html(str);
                           }
                        }
                        );
                        function change(){
                            // 先清空第二个
                            alert("changge 点击科室");
                            $("#selectDoctor").empty();
                            var keshi =  $("#selectKeshi").find("option:selected").text();
                            if(map[keshi] != null){
                                var str = "";
                                var list = map[keshi];
                                for(var i = 0; i < list.length; i++){
                                    var s = list[i];
                                    str += "\"<option>\"+s+\"</option>\"";
                                }
                                $("#selectDoctor").html(str);
                            }
                        }
                    }
                });
            }
        });
    }
    //点击保存按钮，保存返回
    function update(){
        $.ajax({
            type: "POST",//这里必须写POST
            url: "/hosregister/updateHosregister.do",
            data: $("#myForm").serialize()+"&_method=PUT",
            dataType:"json",
            success: function(vo){
                if(vo.code==200) {
                    alert("保存成功！");
                    window.location.href="/registration/index.html?pageNumber="+pageNumber+"&pageSize="+pageSize;
                }else{
                    alert("更新失败！"+vo.msg);
                }
            }
        });
    }
    </script>
</head>
<body>
<form action="index.html" id="myForm" method="post" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tbody id="tboby">
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td><input type="text" name="hosR_id" value="陆小凤"/></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input type="text" name="hosR_idCar" value="21324324324"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">挂号费</td>
        <td><input type="text" name="hosR_regPrice" value="5"/>元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td><input type="text" name="hosR_medical" value="453253453"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td><input type="text" name="hosR_phone" value="13543235678"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input type="radio" name="hosR_selfPrice" id="radioNo" value="" checked/>否&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosR_selfPrice" id="radioYes" value=""/>是</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="hosR_sex" value="" checked/>男&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosR_sex" value=""/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="hosR_age" value="33"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">职业</td>
        <td><input type="text" name="hosR_work" value="狗仔队"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input type="radio" name="hosR_lookDoctor" value="" checked/>初诊&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosR_lookDoctor" value=""/>复诊</td>
    </tr>
    <tr id='selKeshi'>
        <td width="10%" >所挂科室</td>
        <td><select name="selectKeshi" id='selectKeshi' onchange="chang()"  class='selKeshi'><option>急诊科</option><option>骨科</option><option>血液科</option></select></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td><select  name="selectDoctor" id='selectDoctor' class="selDoctor"><option>程俊</option><option>欧阳雨露</option><option>王博</option></select></td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea name="hosR_state">此人疑拟有精神病</textarea></td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button type="submit" class="btn btn-primary" type="button" onclick="update()">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
			</center>
		</td>
    </tr>
    </tbody>
</table>
    <input type="hidden" id="editHosR_id" name="editHosR_id" value="1"/>
</form>
</body>
</html>